package com.huage.courseplatform.application.controller;


import com.huage.courseplatform.application.model.dto.BusinessDTO;
import com.huage.courseplatform.application.model.dto.TeacherDTO;
import com.huage.courseplatform.application.model.entity.Business;
import com.huage.courseplatform.application.model.entity.Teacher;
import com.huage.courseplatform.application.model.param.BusinessApplyPARAM;
import com.huage.courseplatform.application.model.param.TeacherApplyPARAM;
import com.huage.courseplatform.application.service.ApplyAccountService;
import com.huage.courseplatform.framework.annotation.RepeatSubmit;
import com.huage.courseplatform.framework.utils.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;


@RestController
@RequestMapping(value = "/apply")
@Api(tags = "注册接口")
@Slf4j
public class ApplyAccountController {

    @Resource
    ApplyAccountService applyAccountService;

    @RepeatSubmit
    @ApiOperation(value = "商家注册申请")
    @PostMapping(value = "/applyBusiness")
    public ResultUtils<BusinessDTO> applyBusiness(@RequestBody @Validated BusinessApplyPARAM businessApplyPARAM) {
        Business business = new Business();
        BeanUtils.copyProperties(businessApplyPARAM,business);
        applyAccountService.applyBusiness(businessApplyPARAM.getUserId(),business);
        BusinessDTO businessDTO = new BusinessDTO();
        BeanUtils.copyProperties(business,businessDTO);
        return ResultUtils.success(businessDTO);

    }

    @RepeatSubmit
    @ApiOperation(value = "教师注册申请")
    @PostMapping(value = "/applyTeacher")
    public ResultUtils<TeacherDTO> applyTeacher(@RequestBody @Validated TeacherApplyPARAM teacherApplyPARAM) {
        Teacher teacher = new Teacher();
        BeanUtils.copyProperties(teacherApplyPARAM,teacher);
        applyAccountService.applyTeacher(teacherApplyPARAM.getUserId(),teacher);
        TeacherDTO teacherDTO = new TeacherDTO();
        BeanUtils.copyProperties(teacher,teacherDTO);
        return ResultUtils.success(teacherDTO);
    }
}
